﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.ComFun;
using ComLib.ConfigService;
using LogLib;
using ComLib.ComType;

namespace IPCPages
{
    /// <summary>
    /// 拍照选项
    /// </summary>
    public class TakePhotoOption : IniConfigBase
    {
        public TakePhotoOption()
            : base()
        {
        }

        /// <summary>
        /// 倒计时时间间隔，ms
        /// </summary>
        public int CountdownInterval { get; set; } = 1500;

        /// <summary>
        /// 两次拍照动作之间的时间间隔, ms
        /// </summary>
        public int TakingInterval { get; set; } = 6000;

        public override bool Save()
        {
            base.Save();
            SaveField("CountdownInterval", CountdownInterval);
            SaveField("TakingInterval", TakingInterval);
            return true;
        }

        public override bool Load()
        {
            base.Load();
            try
            {
                CountdownInterval = LoadInt32Value("CountdownInterval");
                TakingInterval = LoadInt32Value("TakingInterval");
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("配置文件{0}加载错误:\n\t{1}", ConfigFilePath, ex.Message);
                Log.WriteException(ex.ToString());
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("拍照选项配置: ");       
            FillFieldValueStringDelegate FillString =
                (string field, object val) =>
                {
                    builder.Append("[");
                    builder.Append(field);
                    builder.Append("]: ");
                    builder.Append(val.ToString());
                };
            FillString("倒计时时间间隔", CountdownInterval);
            FillString("两次拍照动作之间的时间间隔", TakingInterval);
            return builder.ToString();
        }
    }
}
